﻿using BW.EatRabbit.API.Application.Commands.Province;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Province
{
    public class GetProvinceQueryCommandHandler : IRequestHandler<GetProvinceQueryCommand, APIResult<List<Province_Information>>>
    {
        private readonly IBaseRepository<Province_Information> _provinceRepository;
        public GetProvinceQueryCommandHandler(IBaseRepository<Province_Information> provinceRepository)
        {

            _provinceRepository = provinceRepository;
        }
        public Task<APIResult<List<Province_Information>>> Handle(GetProvinceQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Province_Information>> result = new APIResult<List<Province_Information>>();

            var list= _provinceRepository.GetAll();
            result.Data = list.ToList();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            return Task.FromResult(result);

        }
    }
}
